import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;

import javax.swing.*;

import Tile.*;

public class GamePanel extends JPanel{
	private static final long serialVersionUID = 1L;
	
	public static final int X_SIZE = 800;
	public static final int Y_SIZE = 520;
	
	Random rand = new Random();
	
	Player player = new Player(40, X_SIZE / 2);
	
	InputHandler input = new InputHandler();
	
	public GamePanel()
	{
		this.setSize(X_SIZE, Y_SIZE);
		this.addKeyListener(input);
	}
	
	public void tick()
	{

	}
	
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		this.setBackground(Color.WHITE);
		
		g.setColor(Color.CYAN);
		g.fillRect(0, 0, X_SIZE, Y_SIZE);
		
		g.setColor(Color.GRAY);
		
		
		//Draw Stone
		for(int y = 0; y < Y_SIZE; y+= 10)
		{
			new StoneTile(0, y).render(g);
			new StoneTile(X_SIZE - Tile.TILE_SIZE, y).render(g);
		}
		for(int x = 0; x < X_SIZE; x+= 10)
		{
			new StoneTile(x, 0).render(g);
			new StoneTile(x, Y_SIZE - Tile.TILE_SIZE).render(g);
		}
		
		//Draw Grass
		for(int x = Tile.TILE_SIZE; x < X_SIZE - (Tile.TILE_SIZE * 2) + 1; x++)
		{
			new GrassTile(x, Tile.TILE_SIZE).render(g);
			new GrassTile(x, Y_SIZE - (Tile.TILE_SIZE * 2)).render(g);
		}
		for(int y = Tile.TILE_SIZE; y < Y_SIZE - (Tile.TILE_SIZE * 2) + 1; y++)
		{
			new GrassTile(Tile.TILE_SIZE, y).render(g);
			new GrassTile((X_SIZE - Tile.TILE_SIZE) - Tile.TILE_SIZE, y).render(g);
		}
		
		//Draw Sand
		for(int x = Tile.TILE_SIZE * 2; x < X_SIZE - (Tile.TILE_SIZE * 3) + 1; x++)
		{
			new SandTile(x, Tile.TILE_SIZE * 2).render(g);
			new SandTile(x, Y_SIZE - (Tile.TILE_SIZE * 3)).render(g);
		}
		for(int y = Tile.TILE_SIZE * 2; y < Y_SIZE - (Tile.TILE_SIZE * 3); y++)
		{
			new SandTile(Tile.TILE_SIZE * 2, y).render(g);
			new SandTile((X_SIZE - Tile.TILE_SIZE) - Tile.TILE_SIZE * 2, y).render(g);
			
		}
		
		player.render(g);
		
	}
}
